﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Question1
{
    class Program
    {
        static void Main(string[] args)
        {
            Rectangle r1 = new Square(10);
            Console.WriteLine("The area of r1：" + r1.GetArea());

            Rectangle r2 = new Rectangle(10, 20);
            Console.WriteLine("The area of r2：" + r2.GetArea());

            Triangle t1 = new Triangle(3,4,5);
            if (t1.IsTri())
                Console.WriteLine("The area of t1：" + t1.GetArea());

            Triangle t2 = new Triangle(2,2,5);
            if(t2.IsTri())
                Console.WriteLine("The area of t2：" + t2.GetArea());
        }
    }

    public interface Area
    {
        double GetArea();
    }

    public class Rectangle : Area
    {
        public Rectangle() { }
        public Rectangle(double length,double width)
        {
            if (length > 0 && width > 0)
            {
                this.length = length;
                this.width = width;
            }
            else
                Console.WriteLine("数据不合法");
        }
        protected double length;
        protected double width;
        public double Length
        {
            get { return length; }
        }
        public double Width
        {
            get { return width; }
        }
        public double GetArea()
        {
            return length * width;
        }
        public void isSquare()
        {
            if (length == width)
                Console.WriteLine("这是一个正方形");
            else
                Console.WriteLine("这是一个长方形");
        }
    }

    public class Square : Rectangle
    {
        public Square(double side) : base(side, side) { }
    }

    public class Triangle:Area
    {
        private double a;
        private double b;
        private double c;
        public double A
        {
            get { return a; }
        }
        public double B
        {
            get { return b; }
        }
        public double C
        {
            get { return c; }
        }
        public Triangle() { }
        public Triangle(double a,double b,double c)
        {
            if (IsTri(a,b,c))
            {
                this.a = a;
                this.b = b;
                this.c = c;
            }
            else
                Console.WriteLine("数据不合法");
        }
        public double GetArea()
        {
            double p = (a + b + c) / 2;
            return Math.Sqrt(p * (p - a) * (p - b) * (p - c));
        }
        public bool IsTri(double a,double b,double c)
        {
            if ((a + b > c) && (b + c > a) && (a + c > b))
                return true;
            else
                return false;
        }
        public bool IsTri()
        {
            if ((a + b > c) && (b + c > a) && (a + c > b)&&(a>0)&&(b>0)&&(c>0))
                return true;
            else
                return false;
        }
    }
}
